/*
 * @(#)ContextModel.java
 *
 * @author <a href="gubarevs@apollo.lv">Denis Gubarev</a>
 */

package com.gshappcore.model;

public class ContextModel extends Model {

    public static final String CONTEXT = "_context";
    public static final String URL = "url";
    public static final String VIEW = "view";

    public ContextModel() {
    }

   public ContextModel(String url, String view) {
        set("url", url);
        set("view", view);
    }

    public Model attachTo(Model model) {
        if (model == this) {
            throw new IllegalArgumentException("Context cannot be attached to itself");
        }
        model.set(CONTEXT, this);
        return model;
    }

    public String getUrl() {
        return getString(URL);
    }

    public String getView() {
        return getString(VIEW);
    }

    public static ContextModel getFrom(Model model) {
        return (ContextModel) model.getModel(CONTEXT);
    }
}
